package com.solid.mq.service.impl;

import com.solid.mq.service.RabbitConsumerService;
import com.solid.rabbitmq.bean.VipsDelayBean;
import com.solid.rabbitmq.config.DelayRabbitConfig;
import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Package: com.kids.mq.service.impl
 * @Description:
 * @Author: Mr.z
 * @CreatDate: 2020/06/03
 */
@Component
class RabbitConsumerServiceIml implements RabbitConsumerService {
    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Override
    @RabbitListener(queues = "fanoutQueueA")
    public void consumerFanoutA(String message) {
        System.out.println("消费者收到队列A中的消息:" + message);
    }

    @Override
    @RabbitListener(queues = "fanoutQueueB")
    public void consumerFanoutB(String message) {
        System.out.println("消费者收到队列B中的消息:" + message);
    }

    @Override
    @RabbitListener(queues = "directQueueC")
    public void consumerDirectC(String message) {
        System.out.println("消费者收到队列C中的消息:" + message);
    }

    @Override
    @RabbitListener(queues = "directQueueD")
    public void consumerDirectD(String message) {
        System.out.println("消费者收到队列D中的消息:" + message);
    }

    @Override
    @RabbitListener(queues = {DelayRabbitConfig.ORDER_QUEUE_NAME})
    public void vipsDelayQueue(VipsDelayBean vipCards, Message message, Channel channel) {
        log.info("###########################################");
        log.info("【vipsDelayQueue 监听的消息】 - 【消费时间】 - [{}]- 【订单内容】 - [{}]", new Date(), vipCards.toString());
        log.info("【收到的过期会员ID】" + vipCards.getId());
        log.info("###########################################");
        // todo  已经消费的的消息删除
    }
}
